/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.zentello.sbot;

import java.util.HashMap;
import java.util.Map;
import static com.zentello.util.Log.*;
/**
 *
 * @author anthony
 */
public abstract class SBOT_LCC {

    /**
     * Called when the life cycle class is created. This is the first method that is called and should be used to do setup before the main logic is called.
     */
    public void setup(){
    }
    
    /**
     * The last method to be called before the object is destroyed. Clean up should be done here. 
     */
    public void teardown(){
    }

    /**
     * A general method to be called for log messages.
     * @param message 
     */
    public abstract void log(String message);

    private Map<String, Object> globalStore, localStore = new HashMap<String, Object>();
    
    protected final void setParameters(Map<String,Object> parameters){
        if(parameters!=null) this.localStore = parameters;        
    }
    
    protected final void setStringParameters(Map<String,String> strParams){
        if(strParams!=null) localStore.putAll(strParams);
    }

    /**
     * Used to access test parameters.
     * If the parameter is not found locally the suite is checked for the parameter.
     * @param key
     * @return Parameter value
     */
    public final Object get(String key){
        debug("get:"+key);
        if(localStore!=null){
            if(localStore.containsKey(key)){
                //debug("local return:"+parameters.get(key));
                return localStore.get(key);
            }
        }
        if(globalStore!=null){
            debug("global return:"+globalStore.get(key));
            return globalStore.get(key);
        }
        debug("return:null");
        return null;
    }

    protected final void setGlobalStore(Map<String, Object> globalStore){
        this.globalStore = globalStore; 
    }
    
    public final void putLocal(String key, Object value){
        if(localStore==null){
            localStore = new HashMap<String, Object>();
        }
        localStore.put(key, value);
        //debug("putLocal:[" + key + "," + value + "]");
    }
    
    public final void putGlobal(String key, Object value){
        if(globalStore!=null){
            globalStore.put(key, value);
            //debug("putGlobal:[" + key + "," + value + "]");
        }
        else{
            //debug("Suite = null! Can't putGlobal:[" + key + "," + value + "]");            
        }
    }

}
